package leecode

import (
	"strconv"
	"strings"
)

func maximumSwap(num int) int {
	strNum := strconv.Itoa(num)
	arr := []byte(strNum)
	for i := 9; i >= 1; i-- {
		if strings.Index(strNum, strconv.Itoa(i)) != -1 {
			index := strings.Index(strNum, strconv.Itoa(i))
			arr[0], arr[index] = arr[index], arr[0]
			break
		}
	}
	str := string(arr)
	res, _ := strconv.Atoi(str)
	return res
}
